﻿using System;
using System.Data.Entity;
using System.Web.Mvc;
using System.Linq;
using CodeContribBlog.Web.Mvc.Areas.Admin.ViewModels;

namespace CodeContribBlog.Web.Mvc.Areas.Admin.Controllers
{
	public class HomeController : AdminController
	{
		public ActionResult Index()
		{
			var now = DateTime.UtcNow;

			var viewModel = new HomeViewModel
				                {
									Blogs = BlogContext.Blogs
										.Select(b => new BlogViewModel
											             {
															 PostCount = b.Posts.Where(x => !x.IsDeleted && x.PublishedAt <= now).Count(),
															 Subtitle = b.Subtitle,
															 Title = b.Title
											             }).ToList()
				                };

			return View("Index", viewModel);
		}
	}
}